package com.yiwei.zxp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.adapter.ShowImagesAdapter;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.view.V19FrameLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class ShowImagesActivity extends BaseActivity {


    @BindView(R.id.pager)
    ViewPager pager;
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    private Unbinder unbiner;
    private ShowImagesAdapter adapter;
    private List<String> Urls;
    private int currentPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_images);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        Intent intent = getIntent();
        currentPosition = intent.getIntExtra("currentPosition", 0);
        Urls = intent.getStringArrayListExtra("data");

        adapter = new ShowImagesAdapter(Urls, this);
        pager.setAdapter(adapter);
        pager.setCurrentItem(currentPosition, false);
        txtTitle.setText(currentPosition + 1 + "/" + Urls.size());
        pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                currentPosition = position;
                txtTitle.setText(currentPosition + 1 + "/" + Urls.size());
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
